﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace SyCODE.Blog
{
    /// <summary>
    /// Directory 的摘要说明
    /// </summary>
    public static class AppPath
    {
        /// <summary>
        /// 获得用户虚拟目录
        /// </summary>
        /// <param name="user">用户名</param>
        /// <returns></returns>
        public static string GetUserVirtualPath(string user)
        {
            return String.Format(@"/u/{0}/{1}/{2}/{3}/", user[0], user[1], user[2], user);
        }

        /// <summary>
        /// 获得用户目录的物理路径
        /// </summary>
        /// <param name="user">用户名</param>
        /// <returns></returns>
        public static string GetUserPhysicalPath(string user)
        {
            return Path.Combine(HttpRuntime.AppDomainAppPath, String.Format(@"u\{0}\{1}\{2}\{3}\", user[0], user[1], user[2], user));
        }

        /// <summary>
        /// 将相对路径转换为物理路径
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static string FromRelativePath(string relativePath)
        {
            return Path.Combine(HttpRuntime.AppDomainAppPath, relativePath.TrimStart('\\'));
        }

        /// <summary>
        /// 将虚拟目录路径转换为物理路径
        /// </summary>
        /// <param name="virtualPath">虚拟目录</param>
        /// <returns></returns>
        public static string FromVirtualPath(string virtualPath)
        {
            return Path.Combine(HttpRuntime.AppDomainAppPath, virtualPath.Replace('/', '\\').TrimStart('\\'));
        }

        /// <summary>
        /// 获得应用程序的根目录物理路径
        /// </summary>
        /// <returns></returns>
        public static string GetAppRootPath()
        {
            return HttpRuntime.AppDomainAppPath;
        }
    }
}